#!/usr/bin/env bash

include() {
  if [ ! -e "$1" ]
  then
    curl -skS "${CI_RUN:-http://mw-gitx.it}/shell/$1" > "$1"
    chmod +x "$1"
  fi
  # shellcheck disable=SC1090
  test "${2^^}" == "TRUE" && . "./$1"
  return 0
}

include ci-feishu.sh
include ci-vars.sh true

status=$(emoji "sparkling heart")
emoji_continue=$(emoji "link")

text="${status} ${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}@${CI_BUILD_REF_NAME}(${CI_JOB_STARTED_AT})\r\n${emoji_continue} ${CI_PROJECT_URL}/-/commit/${CI_COMMIT_SHA} (${CI_COMMIT_AUTHOR}): ${CI_COMMIT_TITLE//\"/\\\"}\r\n${emoji_continue} ${CI_PROJECT_URL}/-/pipelines/${CI_PIPELINE_ID}"

# do not notify on start
# text="$text" ./ci-feishu.sh "$@"
